package tq.com.tqstudent.net;

import org.json.JSONObject;

public class SCHttpResult {
    private int retCode;
    private String errMsg;
    private JSONObject data;

    static public SCHttpResult build(int code, String msg){
        SCHttpResult ret = new SCHttpResult();
        ret.errMsg = msg;
        ret.retCode = code;
        return  ret;
    }


    public int getRetCode() {
        return retCode;
    }

    public void setRetCode(int pRetCode) {
        retCode = pRetCode;
    }

    public String getErrMsg() {
        return errMsg;
    }

    public void setErrMsg(String pErrMsg) {
        errMsg = pErrMsg;
    }

    static public SCHttpResult fromJson(JSONObject pJSONObject){
        SCHttpResult lSCHttpResult = new SCHttpResult();
        lSCHttpResult.retCode = pJSONObject.optInt("retcode");
        lSCHttpResult.errMsg = pJSONObject.optString("errmsg");
        lSCHttpResult.data = pJSONObject.optJSONObject("data");
        return lSCHttpResult;
    }

    public JSONObject getData() {
        return data;
    }

    public void setData(JSONObject pData) {
        data = pData;
    }

    public boolean isSuccess(){
        return (retCode == 0);
    }
    public boolean needLogin(){
        return (retCode == -999);
    }

    static final public SCHttpResult RET_PARAM_ERROR = SCHttpResult.build(-2, "请求参数错误");
    static final public SCHttpResult RET_NET_ERRROR = SCHttpResult.build(-2, "服务器出错");
}
